package de.baumann.browser.activitys.hash

import android.content.Context
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import de.baumann.browser.R
import de.baumann.browser.activitys.center.TurnVipActivity
import de.baumann.browser.adapter.HashRecordAdapter
import de.baumann.browser.api.net.vo.HashValue
import de.baumann.browser.api.net.vo.LoginInfo
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IHashValueView
import de.baumann.browser.present.HashValuePresenter
import de.baumann.browser.utils.getUser
import kotlinx.android.synthetic.main.activity_hash_record.*
import kotlinx.android.synthetic.main.head_hash_record.*
import kotlinx.android.synthetic.main.include_tool_bar.*
import kotlinx.android.synthetic.main.layout_informal_hash.*

/**
 * @author:
 * @date:2018/12/10 17:45
 * @discription: 算力值
 */
class HashValueActivity : BaseOdinActivity<IHashValueView, HashValuePresenter>(), View.OnClickListener, IHashValueView {

    private lateinit var recordAdapter: HashRecordAdapter

    override val startPage = 0
    override fun getAddress(): String {
        val user: LoginInfo? = getUser() ?: return ""
        return user!!.eth_address
    }

    companion object {
        fun startHashValueActivity(context: Context) {
            context.startActivity(Intent(context, HashValueActivity::class.java))
        }
    }

    override fun getTitleText(): String {
        return "算力增长明细"
    }

    override fun getLayout(): Int {
        return R.layout.activity_hash_record
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        rvHashRecord.layoutManager = LinearLayoutManager(mContext)
        recordAdapter = HashRecordAdapter(R.layout.recycler_item_odin_record)
        rvHashRecord.adapter = recordAdapter
        recordAdapter.setEmptyView(R.layout.empty_view, rvHashRecord)
    }

    override fun createPresenter(): HashValuePresenter {
        return HashValuePresenter()
    }

    override fun createView(): IHashValueView {
        return this
    }

    override fun initData() {
        presenter.getHashRecord()
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.tvInformalBuy -> TurnVipActivity.startTurnVipActivity(mContext)
        }
    }

    override fun setHashValues(hashValues: List<HashValue>?) {
        recordAdapter.setNewData(hashValues)
    }
}
